package com.example.action;

import com.example.model.Recvieemailmodel;
import com.example.model.Usermodel;
import com.example.service.RecvieemailService;
import com.example.service.Userservice;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.SessionAware;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;

/**
 * 邮箱控制层
 */
public class RecvieemailAction extends ActionSupport{

    private RecvieemailService es=new RecvieemailService();

    private ArrayList<Recvieemailmodel> list;

    private Recvieemailmodel em;

    public Recvieemailmodel getEm() {
        return em;
    }

    public void setEm(Recvieemailmodel em) {
        this.em = em;
    }

    public ArrayList<Recvieemailmodel> getList() {
        return list;
    }

    public void setList(ArrayList<Recvieemailmodel> list) {
        this.list = list;
    }

    //查询所有信息
    public String query(){
        list=es.query();
        return SUCCESS;
    }

    //新增
    public String add(){
        // 获取当前日期和时间
        Date currentDate = new Date();
        // 创建SimpleDateFormat对象来定义输出格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 使用SimpleDateFormat格式化日期并输出时分秒
        String timeFormatted = sdf.format(currentDate);
        em.setRq(timeFormatted);
        es.add(em);
        return SUCCESS;
    }

    //删除
    public String delete(){
        es.delete(em.getId());
        return SUCCESS;
    }

    //修改
    public String update(){
        es.update(em);
        return SUCCESS;
    }

    //根据ID（辅助查询）
    public String byid(){
        em=es.byid(em.getId());
        return SUCCESS;
    }

}
